package com.example.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.Netfollows;
import com.example.entity.NetfollowsVO;
import com.example.entity.Roles;
import com.example.service.NetfollowsService;

@RequestMapping("/net")
@RestController
public class NetfollowsController {

	@Autowired
	private NetfollowsService netfollowsService;

	
	/**
	 * 多条件查询
	 * @param netfollowsVO
	 * @return
	 */
	@PostMapping("/GetnetfollowsLayUI")
	public Map<String, Object> GetnetfollowsLayUI(NetfollowsVO netfollowsVO){
		Map<String, Object> reMap=new HashMap<String, Object>();
		netfollowsVO.setOffset((netfollowsVO.getPage()-1)*netfollowsVO.getLimit());
		List<Netfollows> list = netfollowsService.GetnetfollowsLayUI(netfollowsVO);
		int count=netfollowsService.getCount(netfollowsVO);
		reMap.put("code","0");
		reMap.put("msg", "success");
		reMap.put("count", count);
		reMap.put("data", list);
		return reMap;
	}
	
	
	@PostMapping("/GetnetfollowsLayUIzixunjingli")
	public Map<String, Object> GetnetfollowsLayUIzixunjingli(NetfollowsVO netfollowsVO){
		Map<String, Object> reMap=new HashMap<String, Object>();
		netfollowsVO.setOffset((netfollowsVO.getPage()-1)*netfollowsVO.getLimit());
		List<Netfollows> list = netfollowsService.GetnetfollowsLayUIzixunjingli(netfollowsVO);
		int count=netfollowsService.getCount1(netfollowsVO);
		reMap.put("code","0");
		reMap.put("msg", "success");
		reMap.put("count", count);
		reMap.put("data", list);
		return reMap;
	}
	
	/**
	 * 按条件查询
	 * 
	 * @param
	 * @return
	 */
	@PostMapping("/selectname")
	public List<Roles> selectname(Roles roles) {
		List<Roles> list = netfollowsService.selectname(roles);
		return list;
	}
	
	/**
	 * 修改用户
	 * @param id
	 * @return
	 */

	@PostMapping(path = "/upNetfollows")
	public Map<String, Object> upNetfollows(Netfollows netfollows) { // 受影响的行数 
		int rows = netfollowsService.upNetfollows(netfollows);
		Map<String, Object> rsMap =new HashMap<String, Object>();
		rsMap.put("code", rows > 0 ? "0" : "1");
		rsMap.put("msg", rows > 0 ? "修改成功" : "修改失败");
		return rsMap;
	}
	
	/**
	 * 根据id删除用户
	 * @param id
	 * @return
	 */
	@PostMapping("/delNetfollows")
	@ResponseBody
	public Map<String, Object> delNetfollows(int id){
		Map<String, Object> relMap=new HashMap<String, Object>();
		int rows=netfollowsService.delNetfollows(id);
		relMap.put("code",rows>0? "0":"1");
		relMap.put("msg",rows>0? "删除成功":"删除失败");
		return relMap;
	}
	
}
